Popular Searches
Popular Course Categories
Popular Courses

Working with SUBTOTAL and AGGREGATE Functions

Working with SUBTOTAL and AGGREGATE Functions

Advanced Mathematical and Statistical Functions

Working with SUBTOTAL and AGGREGATE Functions in Excel

Course: Advanced Excel Training

Topic: Working with SUBTOTAL and AGGREGATE Functions

Course Link: Advanced Excel Course – JustAcademy

Demo Link: Register for a Course Demo

Website: JustAcademy Official Website


1. Introduction to SUBTOTAL and AGGREGATE Functions

Microsoft Excel provides several functions for summarizing, analyzing, and calculating data. Two important functions used in advanced spreadsheet analysis are SUBTOTAL and AGGREGATE.

The SUBTOTAL function calculates summaries such as sums, averages, counts, minimums, and maximums. It is especially useful when working with filtered lists because it excludes rows removed by filters.

The AGGREGATE function provides more advanced calculation options. Depending on the selected operation and options, it can ignore hidden rows, error values, and nested SUBTOTAL or AGGREGATE calculations.

These functions are useful for sales reports, financial statements, inventory analysis, employee records, filtered datasets, and business dashboards.

Learning Objectives

  • Understand the purpose of SUBTOTAL and AGGREGATE.
  • Learn the syntax and arguments of both functions.
  • Calculate sums, averages, counts, minimums, and maximums.
  • Understand how filtering and manually hidden rows affect results.
  • Use AGGREGATE to ignore errors and calculate ranked values.
  • Identify common formula errors and troubleshoot incorrect results.
  • Apply these functions in practical business reporting scenarios.

2. Understanding the SUBTOTAL Function

The SUBTOTAL function calculates a summary for one or more ranges using a specified operation. Unlike a basic SUM formula, SUBTOTAL automatically excludes rows removed by an AutoFilter.

It can also prevent double-counting when its referenced range contains other SUBTOTAL formulas.

Syntax

=SUBTOTAL(function_num, ref1, [ref2], ...)

Arguments Explained

Argument Description Example
function_num A number that identifies the calculation to perform. 9 for SUM
ref1 The first cell range or reference to summarize. B2:B10
ref2 An optional additional range or reference. B12:B20

SUBTOTAL Function Number Reference

Function numbers 1–11 include manually hidden rows, while function numbers 101–111 exclude manually hidden rows. Rows excluded by filtering are ignored by both groups.

Function Number Function Number That Ignores Manually Hidden Rows Operation
1 101 AVERAGE
2 102 COUNT
3 103 COUNTA
4 104 MAX
5 105 MIN
6 106 PRODUCT
7 107 STDEV
8 108 STDEVP
9 109 SUM
10 110 VAR
11 111 VARP

Note: STDEV and STDEVP are legacy function names associated with sample and population standard deviation. For new statistical work, Excel also provides functions such as STDEV.S and STDEV.P.


3. Practical Examples of SUBTOTAL

Example Dataset

Employee Department Sales
Amit Sales 15000
Priya Marketing 12000
Rahul Sales 18000
Neha Finance 10000
Arjun Sales 20000
Sneha Marketing 14000

Assume the dataset is stored in A1:C7, with sales amounts in C2:C7.

Example 1: Calculate Total Sales

=SUBTOTAL(9,C2:C7)

Result: 89000

Function number 9 performs addition. The formula sums all visible sales values and excludes rows removed by an AutoFilter.

Example 2: Calculate Average Sales

=SUBTOTAL(1,C2:C7)

Result: 14833.33

The formula calculates the average of the six sales values.

Example 3: Find the Highest Sales Amount

=SUBTOTAL(4,C2:C7)

Result: 20000

Function number 4 identifies the maximum visible value in the specified range.

Example 4: Find the Lowest Sales Amount

=SUBTOTAL(5,C2:C7)

Result: 10000

This formula returns the minimum visible sales value.

Example 5: Count Numeric Sales Entries

=SUBTOTAL(2,C2:C7)

Result: 6

Function number 2 counts cells containing numeric values in the visible range.

Example 6: Count Non-Blank Employee Names

=SUBTOTAL(3,A2:A7)

Result: 6

Function number 3 counts non-empty cells, making it useful for counting visible employee names or other text entries.


4. Using SUBTOTAL with Filters

One of the most useful features of SUBTOTAL is its ability to update calculations when you filter a dataset.

Step-by-Step Process

  1. Enter your dataset with clearly labeled column headings.
  2. Select the dataset and choose Data > Filter.
  3. Enter a SUBTOTAL formula in a separate summary cell, such as =SUBTOTAL(9,C2:C7).
  4. Open a filter dropdown in the Department column.
  5. Select only the department you want to analyze.
  6. Observe how the subtotal changes to reflect the visible rows.
  7. Clear the filter to return to the total for all records.

Example: Calculate Sales for the Sales Department

When you filter the Department column to show only Sales, the visible sales amounts are 15000, 18000, and 20000.

=SUBTOTAL(9,C2:C7)

Filtered Result: 53000

The formula does not need to be rewritten when the filter selection changes.

SUBTOTAL and Manually Hidden Rows

There is an important difference between filtering rows and hiding them manually:

  • SUBTOTAL(9,C2:C7) includes manually hidden rows but excludes filtered-out rows.
  • SUBTOTAL(109,C2:C7) excludes manually hidden rows as well as filtered-out rows.

Choose the function number based on whether manually hidden records should contribute to the calculation.


5. Understanding the AGGREGATE Function

The AGGREGATE function performs several mathematical and statistical operations, including SUM, AVERAGE, MAX, MIN, MEDIAN, LARGE, and SMALL. It also offers options to ignore hidden rows, errors, and nested summary formulas.

It is particularly valuable when analyzing imperfect datasets that contain error values or when you need ranked calculations such as the second-largest or third-smallest number.

Syntax: Reference Form

=AGGREGATE(function_num, options, ref1, [ref2], ...)

Syntax: Array Form

=AGGREGATE(function_num, options, array, [k])

Arguments Explained

Argument Description
function_num A number from 1 to 19 identifying the calculation.
options A number from 0 to 7 specifying which values or calculations to ignore.
ref1 or array The range, reference, or array containing the data to analyze.
ref2 An optional additional reference for functions that accept multiple numeric arguments.
k The position or rank used by functions such as LARGE, SMALL, PERCENTILE, and QUARTILE.

AGGREGATE Function Number Reference

Function Number Operation
1 AVERAGE
2 COUNT
3 COUNTA
4 MAX
5 MIN
6 PRODUCT
7 STDEV.S
8 STDEV.P
9 SUM
10 VAR.S
11 VAR.P
12 MEDIAN
13 MODE.SNGL
14 LARGE
15 SMALL
16 PERCENTILE.INC
17 QUARTILE.INC
18 PERCENTILE.EXC
19 QUARTILE.EXC

6. Understanding AGGREGATE Options

The options argument determines which rows, errors, and nested calculations should be ignored.

Option Behavior
0 Ignore nested SUBTOTAL and AGGREGATE calculations.
1 Ignore hidden rows and nested SUBTOTAL and AGGREGATE calculations.
2 Ignore error values and nested SUBTOTAL and AGGREGATE calculations.
3 Ignore hidden rows, error values, and nested SUBTOTAL and AGGREGATE calculations.
4 Ignore nothing.
5 Ignore hidden rows only.
6 Ignore error values only.
7 Ignore hidden rows and error values.

Important: These options describe the documented behavior for ordinary reference-based calculations. If the array argument contains a calculated expression rather than a direct reference, hidden-row handling and the treatment of nested calculations can differ. Test complex array formulas against your actual data.


7. Practical Examples of AGGREGATE

Example Dataset

Employee Sales
Amit 15000
Priya 22000
Rahul 18000
Neha 30000
Arjun 25000
Sneha 12000

Assume employee names are in A2:A7 and sales amounts are in B2:B7.

Example 1: Calculate Total Sales

=AGGREGATE(9,0,B2:B7)

Result: 122000

Function number 9 performs SUM, while option 0 ignores nested SUBTOTAL and AGGREGATE calculations.

Example 2: Calculate the Maximum Sales Amount

=AGGREGATE(4,0,B2:B7)

Result: 30000

This formula finds the largest sales value in the range.

Example 3: Calculate the Second-Largest Sales Amount

=AGGREGATE(14,0,B2:B7,2)

Result: 25000

Function number 14 represents LARGE. The final argument, 2, requests the second-largest value.

Example 4: Calculate the Smallest Sales Amount

=AGGREGATE(15,0,B2:B7,1)

Result: 12000

Function number 15 represents SMALL. The final argument, 1, requests the smallest value.

Example 5: Calculate the Median Sales Amount

=AGGREGATE(12,0,B2:B7)

Result: 20000

The median is the middle value when the observations are arranged in ascending order. For an even number of observations, it is the average of the two middle values.

Example 6: Calculate the Average While Ignoring Errors

Suppose B2:B7 contains numeric values and may contain an error such as #DIV/0!.

=AGGREGATE(1,6,B2:B7)

This formula calculates the average while ignoring error values in the referenced range.

For a dataset containing 15000, 22000, #DIV/0!, 30000, 25000, and 12000, the result is approximately 20800.


8. Handling Error Values with AGGREGATE

Real-world Excel datasets can contain errors caused by division by zero, missing references, invalid calculations, or incorrect data imports. Standard functions such as MAX or MIN may return an error if an error value is present in the range.

AGGREGATE can ignore error values when the selected option supports it.

Example: Find the Maximum Value While Ignoring Errors

Suppose the range A1:A6 contains 15000, 22000, #DIV/0!, 30000, #N/A, and 25000.

=AGGREGATE(4,6,A1:A6)

Result: 30000

Function number 4 finds the maximum, and option 6 ignores error values.

Example: Find the Third-Largest Value While Ignoring Errors

=AGGREGATE(14,6,A1:A6,3)

The formula returns the third-largest numeric value after error values are excluded from the calculation.

Important: Ignoring errors is appropriate only when it matches the purpose of the analysis. Error values may indicate important data-quality problems, so investigate them instead of automatically suppressing every error.


9. Difference Between SUBTOTAL and AGGREGATE

Feature SUBTOTAL AGGREGATE
Main purpose Summarize lists and filtered datasets. Perform a broader set of calculations with configurable ignore options.
Available operations 11 operation types, each with two function-number variants. 19 operation types.
Filtered rows Always excluded. Behavior depends on the calculation form and selected options; ordinary reference-based calculations support hidden-row options.
Manually hidden rows Controlled by function numbers 1–11 or 101–111. Controlled by the selected options for supported reference-based calculations.
Error handling Does not provide a dedicated option to ignore errors. Can ignore errors using options such as 2, 3, 6, and 7.
Ranked calculations Does not provide LARGE or SMALL operations. Supports LARGE, SMALL, and percentile or quartile operations.
Nested summaries Ignores nested SUBTOTAL calculations. Can ignore nested SUBTOTAL and AGGREGATE calculations depending on the option.
Best use Dynamic totals for filtered lists. Advanced analysis involving errors, hidden rows, or ranked statistics.

10. Using SUBTOTAL and AGGREGATE in Business Reports

10.1 Sales Reports

Use SUBTOTAL to calculate visible sales totals while managers filter data by region, product, or salesperson.

=SUBTOTAL(109,D2:D100)

This formula calculates the sum of visible sales in D2:D100 and excludes manually hidden rows.

10.2 Financial Analysis

Use AGGREGATE to find maximum, minimum, or ranked financial values when the source data may contain formula errors.

=AGGREGATE(4,6,C2:C100)

This formula returns the maximum numeric value while ignoring errors in the referenced range.

10.3 Inventory Reports

Use SUBTOTAL to summarize visible stock quantities after filtering an inventory list by category or warehouse.

=SUBTOTAL(9,D2:D500)

This formula sums visible values in the stock quantity column.

10.4 Employee Performance Analysis

Use AGGREGATE to identify the second-highest performance score while ignoring error values.

=AGGREGATE(14,6,E2:E100,2)

This formula returns the second-largest numeric score in the range while ignoring errors.

10.5 Dynamic Dashboard Summaries

SUBTOTAL can be combined with dropdown controls and filters to provide changing totals, averages, and counts. AGGREGATE can support dashboard metrics that require error-tolerant maximums, minimums, or rankings.


11. Common Errors and Troubleshooting

Problem Possible Cause Solution
Unexpected SUBTOTAL result The selected function number includes manually hidden rows. Use a function number from 101–111 if manually hidden rows should be excluded.
SUBTOTAL does not change after hiding a row The formula uses a function number that includes manually hidden rows. Use the appropriate 101–111 function number.
AGGREGATE returns #VALUE! A required argument is missing or the arguments are invalid. Check the function number, option, range, and any required k argument.
AGGREGATE returns an unexpected value The wrong operation number or ignore option is selected. Verify the function number and option against the intended calculation.
Errors remain in the result The selected option does not ignore errors, or an array expression behaves differently. Use an appropriate error-ignoring option and test complex array formulas.
Totals are too high Data includes duplicate entries or a formula includes unrelated cells. Validate the range and review the source dataset.
Formula does not update as expected The formula references the wrong range or an outdated dataset. Review cell references and expand the range if necessary.

Best Practices

  • Choose the function number and options according to the reporting requirement.
  • Use clear column headings and consistent data types.
  • Check whether manually hidden rows should be included in the result.
  • Use SUBTOTAL for filtered-list summaries and AGGREGATE for more advanced calculations.
  • Investigate error values before deciding to ignore them.
  • Keep summary formulas outside the data range whenever practical.
  • Test calculations with known values to confirm that the results are correct.

12. Hands-On Practice Exercises

Use the following dataset to practise both functions.

Employee Department Sales
Amit Sales 10000
Priya Marketing 15000
Rahul Sales 20000
Neha Finance 12000
Arjun Sales 25000
Sneha Marketing 18000

Assume the dataset occupies cells A2:C7.

Exercise 1: Calculate Total Sales

=SUBTOTAL(9,C2:C7)

Expected Result: 100000

Exercise 2: Calculate Average Sales

=SUBTOTAL(1,C2:C7)

Expected Result: 16666.67

Exercise 3: Find the Maximum Sales Value

=AGGREGATE(4,0,C2:C7)

Expected Result: 25000

Exercise 4: Find the Second-Largest Sales Value

=AGGREGATE(14,0,C2:C7,2)

Expected Result: 20000

Exercise 5: Count Visible Employee Names

=SUBTOTAL(3,A2:A7)

Expected Result: 6

Exercise 6: Filter the Department Column

Filter the Department column to display only Sales and observe the SUBTOTAL formula.

=SUBTOTAL(9,C2:C7)

Expected Result: 55000

Clear the filter and verify that the total returns to 100000.


13. Mini Project: Build a Dynamic Sales Summary Dashboard

Project Objective: Create an Excel dashboard that summarizes sales data and responds to filters while supporting advanced calculations.

Project Requirements

  1. Create a dataset with employee names, departments, regions, sales amounts, and transaction dates.
  2. Format the data with clear headings and consistent number and date formats.
  3. Enable filters on the dataset.
  4. Use SUBTOTAL to calculate the visible sales total.
  5. Use SUBTOTAL to calculate the average and count of visible records.
  6. Use AGGREGATE to calculate the maximum sales amount while ignoring errors.
  7. Use AGGREGATE to identify the second-highest sales value.
  8. Test the formulas by applying filters and hiding selected rows.
  9. Compare the results with manually verified calculations.

Sample Dashboard Formulas

Visible Sales Total:

=SUBTOTAL(109,D2:D100)

Visible Average Sales:

=SUBTOTAL(101,D2:D100)

Maximum Sales Ignoring Errors:

=AGGREGATE(4,6,D2:D100)

Second-Highest Sales Ignoring Errors:

=AGGREGATE(14,6,D2:D100,2)

Expected Outcomes

  • A filter-responsive sales report.
  • Accurate visible totals and averages.
  • Error-tolerant maximum and ranked calculations.
  • Better understanding of hidden rows and filtered data.
  • A practical example suitable for an Advanced Excel portfolio.

14. Interview Questions and Answers

Q1. What is the SUBTOTAL function in Excel?

Answer: SUBTOTAL calculates a summary such as SUM, AVERAGE, COUNT, MAX, or MIN over one or more ranges. It excludes rows removed by filters.

Q2. What is the AGGREGATE function?

Answer: AGGREGATE performs several mathematical and statistical operations and offers options to ignore hidden rows, errors, and nested summary calculations.

Q3. What is the difference between SUBTOTAL and SUM?

Answer: SUM adds the specified values, including values in filtered-out rows within its range. SUBTOTAL excludes filtered-out rows and can also ignore manually hidden rows depending on the selected function number.

Q4. What is the difference between function numbers 9 and 109?

Answer: Both perform SUM. Function number 9 includes manually hidden rows, while 109 excludes them. Both ignore rows excluded by filters.

Q5. How can AGGREGATE ignore errors?

Answer: Select an option that ignores errors, such as option 6, and choose the required function number.

Q6. How do you calculate the second-largest value using AGGREGATE?

Answer: Use =AGGREGATE(14,0,range,2). Function number 14 selects LARGE, and 2 specifies the second-largest value.

Q7. Does SUBTOTAL count filtered-out rows?

Answer: No. Rows excluded by an AutoFilter are ignored regardless of whether the function number is between 1–11 or 101–111.

Q8. Can AGGREGATE calculate a median?

Answer: Yes. Function number 12 represents MEDIAN.

Q9. Why might AGGREGATE return #VALUE!?

Answer: A required argument may be missing, the function number or option may be invalid, or the formula may not supply the additional argument required by functions such as LARGE and SMALL.

Q10. When should you use SUBTOTAL instead of AGGREGATE?

Answer: Use SUBTOTAL for straightforward summaries of filtered lists. Use AGGREGATE when you need additional operations, error-handling options, or ranked calculations.


15. Quick Revision Checklist

  • SUBTOTAL summarizes visible data and excludes filtered-out rows.
  • Function numbers 1–11 include manually hidden rows.
  • Function numbers 101–111 exclude manually hidden rows.
  • AGGREGATE supports 19 operations.
  • AGGREGATE options control how hidden rows, errors, and nested calculations are treated.
  • Function number 9 performs SUM in both functions.
  • AGGREGATE function number 14 performs LARGE.
  • AGGREGATE function number 15 performs SMALL.
  • AGGREGATE function number 12 calculates MEDIAN.
  • Always verify formula arguments, ranges, and results before using calculations in business reports.

16. Conclusion

SUBTOTAL and AGGREGATE are valuable functions for analyzing data in Microsoft Excel. SUBTOTAL is particularly effective for calculating totals, averages, counts, minimums, and maximums in filtered datasets. AGGREGATE extends these capabilities with additional statistical operations and options for ignoring errors and hidden rows.

Learning both functions enables you to build more reliable reports, analyze large datasets, avoid common double-counting problems, and create dynamic business dashboards. Regular practice with filters, hidden rows, error values, and ranked calculations will help you apply these functions confidently in real-world Excel projects.

Continue Learning: Explore the Advanced Excel Course at JustAcademy, register for a course demo, or visit the JustAcademy official website for more learning resources.

Previous Next
whatsapp